package com.lanou.zakerproject.community;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.lanou.zakerproject.R;
import com.lanou.zakerproject.base.BaseActivity;
import com.lanou.zakerproject.base.VolleySingleton;
import com.lanou.zakerproject.tool.GsonRequest;

/**
 * Created by dllo on 16/1/16.
 */
public class CommunityDetailActivity extends BaseActivity {
    private ListView listView;
    private ChoiceAdapter choiceAdapter;
    private FloatingActionButton floatingActionButton;
    private TextView title_tv;
    private String ID;
    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_community_detail);
        listView = (ListView) findViewById(R.id.listview_community_detail);
        floatingActionButton = (FloatingActionButton) findViewById(R.id.community_comment);
        title_tv = (TextView) findViewById(R.id.community_title);
        Intent intent = getIntent();
        ID = intent.getStringExtra("ID");
        url = "http://dis.myzaker.com/api/get_post.php?discussion_id=" + ID;
        getRequsetData(url);
        Log.d("CommunityDetailActivity", url);
        floatingActionButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(CommunityDetailActivity.this, CommentActivity.class);
                startActivity(intent);
            }
        });
    }

    /**
     * 解析数据的方法
     *
     * @param urls 接口
     */
    private void getRequsetData(String urls) {
        GsonRequest<CommunityData> gsonRequest = new GsonRequest<>(urls, CommunityData.class, new Response.Listener<CommunityData>() {
            @Override
            public void onResponse(CommunityData response) {
                choiceAdapter = new ChoiceAdapter(CommunityDetailActivity.this, response);
                listView.setAdapter(choiceAdapter);
                    title_tv.setText(response.getData().getDiscussion_info().getTitle());
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        VolleySingleton.getInstance()._addRequest(gsonRequest);
    }
}
